Telegram Group & Telegram Channel
Python dasturlash maktabi
Kortej.png
Ⓜ️ Kortejlar (tuple)

# Kortejlar bir nechta ob’yektlarni birgalikda saqlashga xizmat qiladi.

# tuple() funksiyasi, oddiy qavs yoki qavs ochmasdan kortejlarni tuzish mumkin.

tuple_funksiyasi = tuple(['mandarin', 'ananas'])
print(tuple_funksiyasi) # ('mandarin', 'ananas')

qavsli = ('nok', 'shaftoli')
print(qavsli) # ('nok', 'shaftoli')

qavssiz = 'olma', 'anor', 'kadi'
print(qavssiz) # ('olma', 'anor', 'kadi')

# Kortej elementlar orasini vergul bilan ajratish orqali hosil qilinadi.
var1 = ('@pythonuz')
print(type(var1)) # <class 'str'>

var2 = ('@pythonuz',)
print(type(var2)) # <class 'tuple'>


# Kortejning afzalliklari.
1) Kortej o`zgartirishlardan himoyalangan bo`ladi.

# Ro'yxatlarni o'zgartirish mumkin.
royxat = ['@pythonuz', '@phpuz']
royxat[1] = 'js_uz'
print(royxat) # ['@pythonuz', 'js_uz']

# Kortejni ro'yxatdan asosiy farqi korjejlarni o'zgartirib bo'lmaydi.
kortej = ('olma', 'anor')
kortej[1] = 'gilos'
print(kortej) # TypeError: 'tuple' object does not support item assignment

Kortej imkoniyatlari.

# 1) Kortejni ro'yxat turiga o'girib so'ng o'zgartirish kiritish mumkin.
kortej = ('olma', 'anor')
kortejdan_royxatga = list(kortej)
kortejdan_royxatga[1] = 'gilos'
print(kortejdan_royxatga) # ['olma', 'gilos']
royxatdan_kortejga = tuple(kortejdan_royxatga)
print(royxatdan_kortejga) # ('olma', 'gilos')

# 2) Kortej xotiradan kichik hajm band qiladi.

import sys
kortej = ('olma', 1, True)
print(sys.getsizeof(kortej)) # 64
royxat = ['gilos', 0, False]
print(sys.getsizeof(royxat)) # 80

# 3) Kortejdan lug`at kaliti sifatida foydalanish mumkin.

kortej = {(1, True, 'olma'): 7} 
print(kortej[(1, True, 'olma')]) # 7
royxat= {[1, True, 'olma']: 7}
print(royxat[[1, True, 'olma']]) # TypeError: unhashable type: 'list'

# Kvadrat qavs ichidagi indeks raqamiga murojaat qilib kortej elementlarini tanlashingiz mumkin.

kortej = ('olma', 'uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejdagi ikkinchi elelmentni chop qiling
print(kortej[1])  # uzum
# Kortejdagi oxirgi elelmentni chop qiling
print(kortej[-1])  # nok
# Kortejdagi to'rtinchi elelmentdan oltinchi elelmentgacha chop qiling
print(kortej[3:6])  # ('behi', 'anor', "o'rik")
# Kortejdagi beshinchi elelmentgacha chop qiling
print(kortej[:4])  # ('olma', 'uzum', 'gilos', 'behi')
# Kortejdagi iikinchi elelmentdan oxirgi elelmentgacha chop qiling
print(kortej[1:])  # ('uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejalrni birlashtirish.

tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3) # ('a', 'b', 'c', 1, 2, 3)

# Kortejlarni ko'paytirish.
mevalar = ("olma", "banan")
kortej = mevalar * 2
print(kortej) # ('olma', 'banan', 'olma', 'banan')

Kortejda namedtuple subklasidan foydalanish.

@pythonuz



tg-me.com/pythonuz/416
Create:
Last Update:

Ⓜ️ Kortejlar (tuple)

# Kortejlar bir nechta ob’yektlarni birgalikda saqlashga xizmat qiladi.

# tuple() funksiyasi, oddiy qavs yoki qavs ochmasdan kortejlarni tuzish mumkin.

tuple_funksiyasi = tuple(['mandarin', 'ananas'])
print(tuple_funksiyasi) # ('mandarin', 'ananas')

qavsli = ('nok', 'shaftoli')
print(qavsli) # ('nok', 'shaftoli')

qavssiz = 'olma', 'anor', 'kadi'
print(qavssiz) # ('olma', 'anor', 'kadi')

# Kortej elementlar orasini vergul bilan ajratish orqali hosil qilinadi.
var1 = ('@pythonuz')
print(type(var1)) # <class 'str'>

var2 = ('@pythonuz',)
print(type(var2)) # <class 'tuple'>


# Kortejning afzalliklari.
1) Kortej o`zgartirishlardan himoyalangan bo`ladi.

# Ro'yxatlarni o'zgartirish mumkin.
royxat = ['@pythonuz', '@phpuz']
royxat[1] = 'js_uz'
print(royxat) # ['@pythonuz', 'js_uz']

# Kortejni ro'yxatdan asosiy farqi korjejlarni o'zgartirib bo'lmaydi.
kortej = ('olma', 'anor')
kortej[1] = 'gilos'
print(kortej) # TypeError: 'tuple' object does not support item assignment

Kortej imkoniyatlari.

# 1) Kortejni ro'yxat turiga o'girib so'ng o'zgartirish kiritish mumkin.
kortej = ('olma', 'anor')
kortejdan_royxatga = list(kortej)
kortejdan_royxatga[1] = 'gilos'
print(kortejdan_royxatga) # ['olma', 'gilos']
royxatdan_kortejga = tuple(kortejdan_royxatga)
print(royxatdan_kortejga) # ('olma', 'gilos')

# 2) Kortej xotiradan kichik hajm band qiladi.

import sys
kortej = ('olma', 1, True)
print(sys.getsizeof(kortej)) # 64
royxat = ['gilos', 0, False]
print(sys.getsizeof(royxat)) # 80

# 3) Kortejdan lug`at kaliti sifatida foydalanish mumkin.

kortej = {(1, True, 'olma'): 7} 
print(kortej[(1, True, 'olma')]) # 7
royxat= {[1, True, 'olma']: 7}
print(royxat[[1, True, 'olma']]) # TypeError: unhashable type: 'list'

# Kvadrat qavs ichidagi indeks raqamiga murojaat qilib kortej elementlarini tanlashingiz mumkin.

kortej = ('olma', 'uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejdagi ikkinchi elelmentni chop qiling
print(kortej[1])  # uzum
# Kortejdagi oxirgi elelmentni chop qiling
print(kortej[-1])  # nok
# Kortejdagi to'rtinchi elelmentdan oltinchi elelmentgacha chop qiling
print(kortej[3:6])  # ('behi', 'anor', "o'rik")
# Kortejdagi beshinchi elelmentgacha chop qiling
print(kortej[:4])  # ('olma', 'uzum', 'gilos', 'behi')
# Kortejdagi iikinchi elelmentdan oxirgi elelmentgacha chop qiling
print(kortej[1:])  # ('uzum', 'gilos', 'behi', 'anor', "o'rik", 'apelsin', 'shaftoli', 'ananas', 'nok')

# Kortejalrni birlashtirish.

tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
tuple3 = tuple1 + tuple2
print(tuple3) # ('a', 'b', 'c', 1, 2, 3)

# Kortejlarni ko'paytirish.
mevalar = ("olma", "banan")
kortej = mevalar * 2
print(kortej) # ('olma', 'banan', 'olma', 'banan')

Kortejda namedtuple subklasidan foydalanish.

@pythonuz

BY Python dasturlash maktabi


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/pythonuz/416

View MORE
Open in Telegram


Python dasturlash maktabi Telegram | DID YOU KNOW?

Date: |

Export WhatsApp stickers to Telegram on Android

From the Files app, scroll down to Internal storage, and tap on WhatsApp. Once you’re there, go to Media and then WhatsApp Stickers. Don’t be surprised if you find a large number of files in that folder—it holds your personal collection of stickers and every one you’ve ever received. Even the bad ones.Tap the three dots in the top right corner of your screen to Select all. If you want to trim the fat and grab only the best of the best, this is the perfect time to do so: choose the ones you want to export by long-pressing one file to activate selection mode, and then tapping on the rest. Once you’re done, hit the Share button (that “less than”-like symbol at the top of your screen). If you have a big collection—more than 500 stickers, for example—it’s possible that nothing will happen when you tap the Share button. Be patient—your phone’s just struggling with a heavy load.On the menu that pops from the bottom of the screen, choose Telegram, and then select the chat named Saved messages. This is a chat only you can see, and it will serve as your sticker bank. Unlike WhatsApp, Telegram doesn’t store your favorite stickers in a quick-access reservoir right beside the typing field, but you’ll be able to snatch them out of your Saved messages chat and forward them to any of your Telegram contacts. This also means you won’t have a quick way to save incoming stickers like you did on WhatsApp, so you’ll have to forward them from one chat to the other.

What is Telegram?

Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.

Python dasturlash maktabi from ua


Telegram Python dasturlash maktabi
FROM USA